package controller;

import utils.PlayerSides.Sides;
import view.ViewController;

/**
 * Class used to determine if a human-controlled game should end 
 */
public class HumanGameTerminator implements GameTerminator {

	private KingThreat threatAnalyzer; // used to verify game end state
	private ViewController view; // used to for user notifications
	
	/**
	 * Constructor- creates a new game terminator for human-controlled game
	 * @param threatAnalyzer- verifies game ending states
	 * @param view- notifies user
	 */
	public HumanGameTerminator(KingThreat threatAnalyzer, ViewController view) {
		
		// set members according to given values
		this.threatAnalyzer = threatAnalyzer;
		this.view = view;
	}
	
	/**
	 * Ends game if game has reached Checkmate or Stalemate
	 */
	@Override
	public boolean isGameOver(Sides currPlayerSide) {

		// check if Checkmate
		if (threatAnalyzer.isCheckmate(currPlayerSide)) {
			// notify user
			view.notifyGameOver("Checkmate!");
			return true;
		}
		
		// check if Stalemate
		if (threatAnalyzer.isStalemate(currPlayerSide)) {
			// notify user
			view.notifyGameOver("Stalemate!");
			return true;
		}
		
		// game is not over
		return false;
	}
}